package com.mail.server.controller;


import com.mail.model.db.OmsOrderReturnApply;
import com.mail.model.dto.OrderReturnApplyDto;
import com.mail.model.vo.OrderReturnApplyVo;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private OmsOrderReturnApplyService orderReturnApplyService;

    /**
     * 分页查询退货申请
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public R list(OrderReturnApplyDto dto) {
        PageResult result = orderReturnApplyService.list(dto);
        return R.success(result);
    }

    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getOrderReturn(@PathVariable Integer id) {
        OrderReturnApplyVo vo = orderReturnApplyService.getOrderReturn(id);
        return R.success(vo);
    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param orderReturnApply
     * @return
     */
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Integer id, @RequestBody OmsOrderReturnApply orderReturnApply) {
        Integer count = orderReturnApplyService.updateStatus(id, orderReturnApply);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestParam List<Long> ids) {
        Integer count = orderReturnApplyService.delete(ids);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }
}
